    package cn.ffcs.bpm.web;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.opensymphony.xwork2.ActionContext;

import cn.ffcs.base.web.BaseAction;
import cn.ffcs.base.web.PageControl;
import cn.ffcs.bpm.dao.NextTepDAO;
import cn.ffcs.bpm.dao.ProcessConfigDAO;
import cn.ffcs.bpm.dao.ProcessConfigDetailDAO;
import cn.ffcs.bpm.dao.ProcessStepDAO;
import cn.ffcs.bpm.dao.TransactProcessStatusDAO;
import cn.ffcs.bpm.dao.TransactorDAO;
import cn.ffcs.bpm.model.NextTep;
import cn.ffcs.bpm.model.ProcTranRecord;
import cn.ffcs.bpm.model.ProcessConfig;
import cn.ffcs.bpm.model.ProcessConfigDetail;
import cn.ffcs.bpm.model.ProcessStep;
import cn.ffcs.bpm.model.TransactProcessStatus;
import cn.ffcs.bpm.model.Transactor;
import cn.ffcs.bpm.model.TransactorType;
import cn.ffcs.bpm.service.NextTepService;
import cn.ffcs.bpm.service.ProcTranRecordService;
import cn.ffcs.bpm.service.ProcessConfigDetailService;
import cn.ffcs.bpm.service.ProcessConfigService;
import cn.ffcs.bpm.service.ProcessStepService;
import cn.ffcs.bpm.service.TransactProcessStatusService;
import cn.ffcs.bpm.service.TransactorService;
import cn.ffcs.bpm.service.TransactorTypeService;
import cn.ffcs.businessrequest.model.BusinessRequest;
import cn.ffcs.businessrequest.service.BusinessRequestService;
import cn.ffcs.common.model.Attach;
import cn.ffcs.common.service.AttachService;
import cn.ffcs.organ.model.OrgRelaPerson;
import cn.ffcs.organ.model.Person;
import cn.ffcs.organ.service.OrgRelaPersonService;
import cn.ffcs.security.model.User;
import cn.ffcs.util.GetSet;
import cn.ffcs.util.MyList;
import cn.ffcs.util.context.ApplicationContextUtil;

/**
 * 
 * TODO 首页业务需求更多功能<br/> <table>
 * <tr>
 * <td>负责人/principal: </td>
 * <td colspan="2">liuzhh</td>
 * <tr>
 * <td>修改记录/revision:</td>
 * <td colspan="2"></td>
 * </tr>
 * <tr>
 * <td>日期:</td>
 * <td>修改人:</td>
 * <td>修改说明:</td>
 * </tr>
 * <tr>
 * <td></td>
 * <td></td>
 * <td></td>
 * </tr>
 * </table>
 * @author huangjj
 * @version $Id$
 */
public class IndexRequestAction<P extends TransactProcessStatus>
        extends BizProcessManageAction<P>
{
    private static final int BUFFER_SIZE = 512 * 1024;
    /** 流程办理POJO **/
    private P transactProcessStatus;
    /** 办理基本信息POJO **/
    private BusinessRequest businessRequest;
    /** 办理人信息POJO **/
    private Transactor transactor;
    /** 流程历史信息POJO **/
    private ProcTranRecord procTranRecord;
    /** 流程办理状态服务 **/
    private TransactProcessStatusService transactProcessStatusService;
    /** 业务需求基本信息服务 **/
    private BusinessRequestService businessRequestService;
    /** 附件列表数据 **/
    private List<Attach> attachs;
    /** 附件服务 **/
    private AttachService attachService;
    /** 附件上传 **/
    private List<File> uploads;
    /** 上传附件名称 **/
    private List<String> fileNames;
    /** 上传附件名称 **/
    private List<String> uploadContentTypes;

    /** 流程节点服务 **/
    private ProcessConfigDetailService processConfigDetailService;
    /** 流程步骤服务 **/
    private ProcessStepService processStepService;
    /** 流程配置服务 **/
    private ProcessConfigService processConfigService;
    /** 办理人服务 **/
    private TransactorService transactorService;
    /** 办理人类型服务 **/
    private TransactorTypeService transactorTypeService;
    /** 办理人类型服务 **/
    private NextTepService nextTepService;
    /** 办理人类型服务 **/
    private ProcTranRecordService procTranRecordService;
    /** 流程配置数据集 **/
    private List<ProcessConfig> processConfigs;
    /** 流程步骤数据集 **/
    private List<ProcessStep> processSteps;
    /** 办理人类型数据集 **/
    private List<Transactor> transactors;
    /** 办理人类型数据集 **/
    private List<TransactorType> transactorTypes;
    /** 下一节点数据集 **/
    private List<NextTep> nextTeps;
    /** 流程步骤数据集 **/
    private List<ProcessConfigDetail> processConfigDetails;
    /** 流程步骤数据集 **/
    private List<P> transactProcessStatusList;
    /** 流程步骤数据集 **/
    private List<ProcTranRecord> procTranRecords;
    /** 业务流程单数据集 **/
    private List<BusinessRequest> businessRequests;
    /** 业务流程阅办单数据集 **/
    private List<BusinessRequest> yueBusinessRequests;
    /** 组织服务 **/
    private OrgRelaPersonService orgRelaPersonService;
    /** 是否首页,更多 **/
    private String isIndex;
    /** 是否首页,更多 **/
    private String businessType;
    
    /**
     * 初始化业务数据
     * @return
     */
    @SuppressWarnings("unchecked")
    public String init()
    {
        if (businessRequest != null)
        {
            Criterion cond1 = Restrictions.eq("refEntity", businessRequest
                    .getClass().getName());
            Criterion cond2 = Restrictions.eq("refEntityID", businessRequest
                    .getId().toString());
            Criterion condAttach = Restrictions.and(cond1, cond2);
            attachs = attachService.findBy(condAttach);
            Criterion cond3 = Restrictions.eq("refEntityId", businessRequest);
            Criterion condProcTranRecord = Restrictions.and(cond1, cond3);
            procTranRecords = procTranRecordService.findByAndOrder(
                    condProcTranRecord, "id", "asc");
        }
        return SUCCESS;
    }

    /**
     * 查询显示当前操作人员待办单
     * @return
     */
    public String findCurBusinessRequest()
    {
        HashMap<String, Object> conds = super.getConds();
        if (conds == null)
        {
            conds = new HashMap<String, Object>();
        }
        conds.put("transactor.userId", ApplicationContextUtil
                .getUserContextObject().getCurrUser().getPersonID());
        conds.put("transactor.tranType", "1");
        businessRequests = transactorService.findByPage(conds);
        conds.put("transactor.tranType", "3");
        yueBusinessRequests = transactorService.findByPage(conds);
        /** 判断是否首页更多 
        if(isIndex != null && isIndex.equalsIgnoreCase("1"))
        {
            return "listBusinessRequest";
        }**/
        return SUCCESS;
    }

    /**
     * 查询显示当前操作人员已办单
     * @return
     */
    public String eventBusinessRequest()
    {
        HashMap<String, Object> conds = super.getConds();
        if (conds == null)
        {
            conds = new HashMap<String, Object>();
        }
        conds.put("procTranRecord.transactor", ApplicationContextUtil
                .getUserContextObject().getCurrUser().getPersonID());
        businessRequests = businessRequestService.findOrganized(conds);
        if(pageControl==null){
            pageControl=new PageControl(businessRequests.size(),1,10,0);
        }
        else{
            pageControl=new PageControl(businessRequests.size(),pageControl.getPageNo(),10,0);
        }
        businessRequests=this.offset(businessRequests, pageControl.getPageNo(), pageControl.getPageSize());
        /** 判断是否首页更多 
        if(isIndex != null && isIndex.equalsIgnoreCase("1"))
        {
            return "listBusinessRequest";
        }**/
        return SUCCESS;
    }

    /**
     * 编辑操作
     * @return
     */
    public String processBusinessRequest()
    {
        Criterion cond = null;
        cond = Restrictions.gt("id", 0);
        nextTeps = nextTepService.findBy(cond);
        processConfigDetails = processConfigDetailService.findAll();
        User curUser = ApplicationContextUtil.getUserContextObject()
                .getCurrUser();
        // 当为新增流程时，初始化当前流程信息；否则为修改流程时，取流程信息；
        if (businessRequest != null && businessRequest.getId()!=null)
        {
            businessRequest = (BusinessRequest) businessRequestService
                    .findById(businessRequest.getId());
            init();
            cond = Restrictions.eq("refEntityId", businessRequest);
            List list = transactProcessStatusService.findBy(cond);
            if (list != null && list.size() > 0){
                transactProcessStatus = (P) list.get(0);
            }
        }
        else
        {
            businessRequest = new BusinessRequest();
            businessRequest.setStartPerson(curUser.getPerson().getName());
            String pID=curUser.getPersonID();
            //查找所在部门
            Criterion cond1 = Restrictions.eq("person", curUser.getPerson());  
            List<OrgRelaPerson> orps=orgRelaPersonService.findBy(cond1);
            if (orps!=null&&orps.size()>0){
                OrgRelaPerson orp=orps.get(0);
                businessRequest.setStartDept(orp.getOrganization().getName());
            }
            // 新增流程时，初始化信息：状态为开始、当前办理人为操作人，
            transactProcessStatus = (P) new TransactProcessStatus();
            processConfigs = processConfigService.findAll(); // 所属流程信息
            if (curUser != null)
            {
                transactProcessStatus.setCurrTransactor(curUser.getPerson().getName());
            }
        }
        if(isTransactors(transactProcessStatus)){
            return "huiqian";
        }
        return SUCCESS;
    }
    
    /**
     * 
     * 判断当前流程是否有多个用户在处理
     * @return
     */
    public boolean isTransactors(TransactProcessStatus transactProcessStatus){
        if(transactProcessStatus!=null&&transactProcessStatus.getId()!=null){
            Criterion cond1 = null;
            cond1 = Restrictions.eq("currProcess", transactProcessStatus);
            Criterion conds = Restrictions.and(cond1, Restrictions.eq("tranType", "1"));
            List<Transactor> list=transactorService.findBy(conds);
            if(list!=null&&list.size()>=2){
                return true;
            }
        }
        return false;
    }
    
    /**
     * 
     * 根据办理人类型获取办理人
     * @return
     */
    public String viewTransactorByType()
    {
        List list = null;
        if (super.getConds() != null)
        {
            String id = super.getConds().get("id") + "";
            if (!"".equals(id))
            {
                ProcessConfigDetail processConfigDetail = (ProcessConfigDetail) processConfigDetailService
                        .findById(new Integer(id));
                list = findListData(processConfigDetail.getTransactorType());
            }
        }
        ActionContext ctx = ActionContext.getContext();
        HttpServletResponse response = (HttpServletResponse) ctx
                .get(ServletActionContext.HTTP_RESPONSE);
        String xml = MyList.getAll(list);
        response.setCharacterEncoding("gb2312");// 页面编码设置
        response.setContentType("text/xml");// 页面文件头格式
        // System.out.println(xml);
        try
        {
            response.getWriter().write(xml);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return null;
    }

    public List findListData(TransactorType transactorType)
    {
        if (transactorType != null && transactorType.getTaskRealize() != null
                && transactorType.getMethodName() != null
                && transactorType.getParam() != null)
        {
            String[] params = transactorType.getParam().split(",");
            GetSet getSet = new GetSet();
            try
            {
                return (List) getSet.getMethod(Class.forName(
                        transactorType.getTaskRealize()).newInstance(),
                        transactorType.getMethodName(), params);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        return new ArrayList();
    }

    /**
     * 新增或修改操作
     * @param baseEntity
     */
    public String saveOrUpdate()
    {
        boolean flag=true;      //新增标识，true为新增，false为修改
        // 获取附件是否为发布
        String[] publishIDs = getContextObjects("publishIDs");
        String[] attachIDs = getContextObjects("attachIDs");
        // 删除附件
        String[] delIDs = getContextObjects("delIDs");
        User curUser = ApplicationContextUtil.getUserContextObject()
        .getCurrUser();
        if(businessRequest!=null&&businessRequest.getId()!=null){
            flag=false;
        }
        else{
            if (curUser != null)
            {
                transactProcessStatus.setCurrTransactor(curUser.getPerson().getName());
            }
        }
        // 保存数据
        businessRequestService.saveBusinessRequest(businessRequest, uploads,
                fileNames, publishIDs, attachIDs, delIDs);
        transactProcessStatus.setRefEntityId(businessRequest);
        transactProcessStatus.setRefEntity(businessRequest.getClass().getName());

        baseService.saveOrUpdate(transactProcessStatus);
        if(flag){       //新增的时候，保存当前操作人为待办人;修改时不处理
            Transactor transactor = new Transactor();
            transactor.setTranType("1");
            transactor.setCurrProcess(transactProcessStatus);
            Person person = new Person();
            person.setId(new Integer(curUser.getPersonID()));
            transactor.setUserId(person);
            transactorService.save(transactor);
        }
        
        return processBusinessRequest();
    }

    /**
     * 提交流程申请
     * @param baseEntity
     */
    public String submitProcess()
    {
        if(businessRequest!=null&&businessRequest.getId()!=null){
            setRequestParam("businessRequestId", businessRequest.getId()+"");
        }
        User curUser=ApplicationContextUtil.getUserContextObject().getCurrUser();
        if (transactProcessStatus == null||transactProcessStatus.getCurrTransactor()==null||curUser==null){
//            processBusinessRequest();
            this.returnMsg="操作失败！";
            this.returnUrl=null;
            return SUCCESS;
        }

        // 获取附件是否为发布
        String[] publishIDs = getContextObjects("publishIDs");
        String[] attachIDs = getContextObjects("attachIDs");
        // 删除附件
        String[] delIDs = getContextObjects("delIDs");
        // 保存数据
        businessRequestService.saveBusinessRequest(businessRequest, uploads,
                fileNames, publishIDs, attachIDs, delIDs);

        // 提交申请后，当前流程信息改为前一流程信息，前一流程信息入历史表
        transactProcessStatus.setRefEntityId(businessRequest);
        transactProcessStatus
                .setRefEntity(businessRequest.getClass().getName());
        fillProcTranRecord(1, "");
        ///当前代办人为多人时，为会签办理，只有当最后一个人提交的时候，流程才转入下一步骤
        boolean nextFlag=true;
        nextFlag=!isTransactors(transactProcessStatus);
        
        if(nextFlag){
            toNextConfig();
            baseService.saveOrUpdate(transactProcessStatus);
        }
        if(transactProcessStatus!=null&&transactProcessStatus.getId()!=null){
            HashMap<String, Object> conds=new HashMap();
            conds.put("currProcess",transactProcessStatus.getId() + "");
            conds.put("userId",curUser.getPersonID() + "");
            
            transactorService.remove(null, conds);
        }
        if(!nextFlag){
            this.returnMsg="操作成功！<br><br>流程已成功提交！";
            return SUCCESS;
        }
        String nextPerson = getContextObject("nextPerson");
        
        if (transactProcessStatus.getCurrTransactor() != null)
        {
            if (nextPerson == null || "".equals(nextPerson))
            {
                nextPerson = curUser.getPersonID();
            }
            String[] ps = nextPerson.split(",");
            for (String pp : ps)
            {
                Transactor transactor = new Transactor();
                transactor.setTranType("1");
                transactor.setCurrProcess(transactProcessStatus);
                Person person = new Person();
                person.setId(new Integer(pp));
                transactor.setUserId(person);
                transactorService.saveOrUpdate(transactor);
            }
            String persons = getContextObject("persons");
            if (persons != null && !"".equals(persons))
            {
                String[] pss = persons.split(",");
                for (String pp : pss)
                {
                    Transactor transactor = new Transactor();
                    transactor.setTranType("3");
                    transactor.setCurrProcess(transactProcessStatus);
                    Person person = new Person();
                    person.setId(new Integer(pp));
                    transactor.setUserId(person);
                    transactorService.saveOrUpdate(transactor);
                }
            }
        }
//        processBusinessRequest();
        this.returnMsg="操作成功！<br><br>流程已成功提交！";
        if(businessRequest!=null&&businessRequest.getId()!=null){
            this.returnUrl="/bpm/processBusinessRequest.action?businessRequest.id="+businessRequest.getId();
        }
        return SUCCESS;
    }
    

    // 将前一流程信息填写入历史表
    public void fillProcTranRecord(int orderby, String transactorInfo)
    {
        procTranRecord = new ProcTranRecord();
        procTranRecord.setOrderBy(orderby);
        procTranRecord.setRefEntity(transactProcessStatus.getRefEntity());
        procTranRecord.setRefEntityId(transactProcessStatus.getRefEntityId());
        procTranRecord.setProcessStep(transactProcessStatus
                .getCurrProcessConfigDetail());
        procTranRecord.setProcessConfig(transactProcessStatus
                .getCurrProcessConfig());
        Person person = new Person();
        person.setId(new Integer(ApplicationContextUtil.getUserContextObject()
                .getCurrUser().getPersonID()));
        procTranRecord.setTransactor(person);
        if ("".equals(transactorInfo))
        {
            procTranRecord.setTransactInfo(getContextObject("transactorInfo"));
        }
        else
        {
            procTranRecord.setTransactInfo(transactorInfo);
        }
        procTranRecord.setTransactTime(baseService.getCurrSysdate());
        procTranRecordService.saveOrUpdate(procTranRecord);
    }

    // 将当前流程信息替换前一流程信息,下一步骤信息写入当前流程信息
    public void toNextConfig()
    {
        transactProcessStatus.setPreProcessConfig(transactProcessStatus
                .getCurrProcessConfig());
        transactProcessStatus.setPreProcessConfigDetail(transactProcessStatus
                .getCurrProcessConfigDetail());
        transactProcessStatus.setPreProcessStep(transactProcessStatus
                .getCurrProcessStep());
        transactProcessStatus.setPreTransactor(transactProcessStatus
                .getCurrTransactor());

        String processConfigDetailId = getContextObject("nextStep");

        ProcessConfigDetail currProcessConfigDetail = (ProcessConfigDetail) processConfigDetailService
                .findById(new Integer(processConfigDetailId));
        transactProcessStatus
                .setCurrProcessConfigDetail(currProcessConfigDetail);
        if (currProcessConfigDetail == null
                || "1".equals(currProcessConfigDetail.getNodeType()))
        {
            transactProcessStatus.setCurrTransactor(null);
        }
        else if (getContextObject("nextPersonName") != null
                && !"".equals(getContextObject("nextPersonName")))
        {
            transactProcessStatus
                    .setCurrTransactor(getContextObject("nextPersonName"));
        }
        else
        {
            transactProcessStatus.setCurrTransactor(ApplicationContextUtil
                    .getUserContextObject().getCurrUser().getUserID());
        }
    }

    // 上一个流程节点填入当前节点；
    public void toPreConfig()
    {
        transactProcessStatus.setPreProcessConfig(transactProcessStatus
                .getCurrProcessConfig());
        transactProcessStatus.setPreProcessConfigDetail(transactProcessStatus
                .getCurrProcessConfigDetail());
        transactProcessStatus.setPreProcessStep(transactProcessStatus
                .getCurrProcessStep());
        transactProcessStatus.setPreTransactor(transactProcessStatus
                .getCurrTransactor());

        transactProcessStatus.setCurrProcessConfig(transactProcessStatus
                .getPreProcessConfig());
        transactProcessStatus.setCurrProcessConfigDetail(transactProcessStatus
                .getPreProcessConfigDetail());
        transactProcessStatus.setPreProcessStep(transactProcessStatus
                .getCurrProcessStep());
        transactProcessStatus.setCurrTransactor(transactProcessStatus
                .getPreTransactor());
    }

    /**
     * 流程申请回退
     * @param baseEntity
     */
    public String backProcess()
    {
        backToPre("回退");
        return SUCCESS;
    }

    /**
     * 流程申请回收 要求办理人是当前操作人，当前节点是开始节点的，才允许回收 删除流程办理信息、办理人信息、增加一条回收的历史记录
     */
    public String removeProcess(){
        backToPre("回收");
        processBusinessRequest();
        return SUCCESS;
    }

    /**
     * 流程申请删除
     */
    public String deleteProcess()
    {
        if (businessRequest != null&&businessRequest.getId()!=null)
        {
            Criterion cond1 = Restrictions.eq("refEntity", businessRequest.getClass().getName());
            Criterion cond2 = Restrictions.eq("refEntityId", businessRequest);
            Criterion conds = Restrictions.and(cond1, cond2);
            List<TransactProcessStatus> list=transactProcessStatusService.findBy(conds);
            if(list!=null){
                for(int i=0;i<list.size();i++){
                    transactProcessStatus=(P)list.get(i);
                    HashMap<String, Object> condTemp= super.getConds();
                    if (condTemp==null) {
                        super.setConds(new HashMap<String, Object>());
                    }
                    super.getConds().put("currProcess",transactProcessStatus.getId() + "");
                    transactorService.remove(null, super.getConds());
                    fillProcTranRecord(0, "删除");
                    transactProcessStatusService.remove(transactProcessStatus);
                }
            }
            businessRequestService.remove(businessRequest);
        }
        return SUCCESS;
    }

    /**
     * 批量删除
     * @return
     */
    public String batchDel()
    {
        String[] ids = getContextObjects("ids");
        if(ids!=null&&ids.length>0){
            if(businessRequest==null)
                businessRequest=new BusinessRequest();
            for(int i=0;i<ids.length;i++){
                businessRequest.setId(new Integer(ids[i]));
                this.deleteProcess();
            }
        }
        returnMsg = "批量删除操作已成功！";
        return SUCCESS;
    }
    
    
    public String backToPre(String info)
    {
        if (transactProcessStatus == null
                || transactProcessStatus.getId() == null
                || "".equals(transactProcessStatus.getId()))
        {
            return SUCCESS;
        }
        transactProcessStatus = (P) transactProcessStatusService
                .findById(new Integer(transactProcessStatus.getId()));
        // /当前节点为开始节点时，不处理回退操作；否则转上一步骤
        if ("0".equals(transactProcessStatus.getCurrProcessConfigDetail()
                .getNodeType()))
        {
            return SUCCESS;
        }
        // 判断上一个流程节点不为空时，当前节点入历史表，上一个流程节点填入当前节点；
        if (transactProcessStatus.getPreProcessConfigDetail() != null
                && !""
                        .equals(transactProcessStatus
                                .getPreProcessConfigDetail()))
        {
            // 从历史记录中恢复流程信息
            if (businessRequest != null)
            {
                Criterion cond1 = Restrictions.eq("refEntity", businessRequest
                        .getClass().getName());
                Criterion cond2 = Restrictions.eq("orderBy", 1);
                Criterion cond3 = Restrictions.eq("refEntityId",
                        businessRequest);
                Criterion condProcTranRecord = Restrictions.and(cond1, cond2);
                condProcTranRecord = Restrictions
                        .and(condProcTranRecord, cond3);
                procTranRecords = procTranRecordService.findByAndOrder(
                        condProcTranRecord, "id", "desc");
                fillProcTranRecord(0, info);
                if (procTranRecords != null)
                {
                    if (procTranRecords.size() > 0
                            && procTranRecords.get(0).getTransactor() != null)
                    {
                        transactProcessStatus
                                .setCurrProcessConfig(transactProcessStatus
                                        .getPreProcessConfig());
                        transactProcessStatus
                                .setCurrProcessConfigDetail(transactProcessStatus
                                        .getPreProcessConfigDetail());
                        transactProcessStatus
                                .setCurrTransactor(transactProcessStatus
                                        .getPreTransactor());
                        transactProcessStatus
                                .setPreProcessStep(transactProcessStatus
                                        .getPreProcessStep());
                        procTranRecord = procTranRecords.get(0);
                        
                        transactorService.saveTransactor(procTranRecord
                                .getTransactor().getId()
                                + "", "1", transactProcessStatus);
                        procTranRecord.setOrderBy(0);
                        procTranRecordService.saveOrUpdate(procTranRecord);
                        if (procTranRecords.size() > 1
                                && procTranRecords.get(1) != null)
                        {
                            procTranRecord = procTranRecords.get(1);
                        }
                        else
                        {
                            procTranRecord = new ProcTranRecord();
                        }

                        transactProcessStatus
                                .setPreProcessConfig(procTranRecord
                                        .getProcessConfig());
                        transactProcessStatus
                                .setPreProcessConfigDetail(procTranRecord
                                        .getProcessStep());
                        if (procTranRecord.getTransactor() != null)
                            transactProcessStatus
                                    .setPreTransactor(procTranRecord
                                            .getTransactor().getName());
                        else
                            transactProcessStatus.setPreTransactor(null);
                        transactProcessStatusService
                                .saveOrUpdate(transactProcessStatus);
                    }
                }
            }
        }
        return SUCCESS;
    }

    public List offset(List list,int pageNo,int pageSize){
        int offset=0;
        int subNo=0;
        
        if(list.size()>=pageNo*pageSize){
            offset=(pageNo-1)*pageSize+1;
        }else{
            offset=list.size()/pageSize*pageSize;
        }
        if(list.size()>pageNo*pageSize){
            subNo=offset+pageSize;
        }else{
            subNo=list.size();
        }
        return list.subList(offset,subNo);
    }
    
    public String toSuccess(){
        return SUCCESS;
    }
    
    public String setRequestParam(String name,String param){
        ActionContext ctx = ActionContext.getContext();
        HttpServletRequest request = (HttpServletRequest) ctx
                .get(ServletActionContext.HTTP_REQUEST);
        request.setAttribute(name, param);
        return SUCCESS;
    }
    
    /**
     * 删除操作
     * @return
     */
    public String remove()
    {
        baseService.remove(transactProcessStatus);
        return SUCCESS;
    }

    public P getTransactProcessStatus()
    {
        return transactProcessStatus;
    }

    public void setTransactProcessStatus(P transactProcessStatus)
    {
        this.transactProcessStatus = transactProcessStatus;
    }

    public BusinessRequestService getBusinessRequestService()
    {
        return businessRequestService;
    }

    public void setBusinessRequestService(
            BusinessRequestService businessRequestService)
    {
        this.businessRequestService = businessRequestService;
    }

    public TransactProcessStatusService getTransactProcessStatusService()
    {
        return transactProcessStatusService;
    }

    public void setTransactProcessStatusService(
            TransactProcessStatusService transactProcessStatusService)
    {
        this.transactProcessStatusService = transactProcessStatusService;
    }

    public AttachService getAttachService()
    {
        return attachService;
    }

    public void setAttachService(AttachService attachService)
    {
        this.attachService = attachService;
    }

    public List<Attach> getAttachs()
    {
        return attachs;
    }

    public void setAttachs(List<Attach> attachs)
    {
        this.attachs = attachs;
    }

    public List<String> getFileNames()
    {
        return fileNames;
    }

    public void setFileNames(List<String> fileNames)
    {
        this.fileNames = fileNames;
    }

    public List<String> getUploadContentTypes()
    {
        return uploadContentTypes;
    }

    public void setUploadContentTypes(List<String> uploadContentTypes)
    {
        this.uploadContentTypes = uploadContentTypes;
    }

    public List<File> getUpload()
    {
        return uploads;
    }

    public void setUpload(List<File> uploads)
    {
        this.uploads = uploads;
    }

    public List<String> getUploadFileName()
    {
        return fileNames;
    }

    public void setUploadFileName(List<String> fileNames)
    {
        this.fileNames = fileNames;
    }

    public BusinessRequest getBusinessRequest()
    {
        return businessRequest;
    }

    public void setBusinessRequest(BusinessRequest businessRequest)
    {
        this.businessRequest = businessRequest;
    }

    public List<NextTep> getNextTeps()
    {
        return nextTeps;
    }

    public void setNextTeps(List<NextTep> nextTeps)
    {
        this.nextTeps = nextTeps;
    }

    public NextTepService getNextTepService()
    {
        return nextTepService;
    }

    public void setNextTepService(NextTepService nextTepService)
    {
        this.nextTepService = nextTepService;
    }

    public ProcessConfigDetailService getProcessConfigDetailService()
    {
        return processConfigDetailService;
    }

    public void setProcessConfigDetailService(
            ProcessConfigDetailService processConfigDetailService)
    {
        this.processConfigDetailService = processConfigDetailService;
    }

    public List<ProcessConfig> getProcessConfigs()
    {
        return processConfigs;
    }

    public void setProcessConfigs(List<ProcessConfig> processConfigs)
    {
        this.processConfigs = processConfigs;
    }

    public ProcessConfigService getProcessConfigService()
    {
        return processConfigService;
    }

    public void setProcessConfigService(
            ProcessConfigService processConfigService)
    {
        this.processConfigService = processConfigService;
    }

    public List<ProcessStep> getProcessSteps()
    {
        return processSteps;
    }

    public void setProcessSteps(List<ProcessStep> processSteps)
    {
        this.processSteps = processSteps;
    }

    public ProcessStepService getProcessStepService()
    {
        return processStepService;
    }

    public void setProcessStepService(ProcessStepService processStepService)
    {
        this.processStepService = processStepService;
    }

    public List<TransactorType> getTransactorTypes()
    {
        return transactorTypes;
    }

    public void setTransactorTypes(List<TransactorType> transactorTypes)
    {
        this.transactorTypes = transactorTypes;
    }

    public TransactorTypeService getTransactorTypeService()
    {
        return transactorTypeService;
    }

    public void setTransactorTypeService(
            TransactorTypeService transactorTypeService)
    {
        this.transactorTypeService = transactorTypeService;
    }

    public List<P> getTransactProcessStatusList()
    {
        return transactProcessStatusList;
    }

    public void setTransactProcessStatusList(List<P> transactProcessStatusList)
    {
        this.transactProcessStatusList = transactProcessStatusList;
    }

    public List<ProcessConfigDetail> getProcessConfigDetails()
    {
        return processConfigDetails;
    }

    public void setProcessConfigDetails(
            List<ProcessConfigDetail> processConfigDetails)
    {
        this.processConfigDetails = processConfigDetails;
    }

    public ProcTranRecord getProcTranRecord()
    {
        return procTranRecord;
    }

    public void setProcTranRecord(ProcTranRecord procTranRecord)
    {
        this.procTranRecord = procTranRecord;
    }

    public TransactorService getTransactorService()
    {
        return transactorService;
    }

    public void setTransactorService(TransactorService transactorService)
    {
        this.transactorService = transactorService;
    }

    public ProcTranRecordService getProcTranRecordService()
    {
        return procTranRecordService;
    }

    public void setProcTranRecordService(
            ProcTranRecordService procTranRecordService)
    {
        this.procTranRecordService = procTranRecordService;
    }

    public List<ProcTranRecord> getProcTranRecords()
    {
        return procTranRecords;
    }

    public void setProcTranRecords(List<ProcTranRecord> procTranRecords)
    {
        this.procTranRecords = procTranRecords;
    }

    public Transactor getTransactor()
    {
        return transactor;
    }

    public void setTransactor(Transactor transactor)
    {
        this.transactor = transactor;
    }

    public List<Transactor> getTransactors()
    {
        return transactors;
    }

    public void setTransactors(List<Transactor> transactors)
    {
        this.transactors = transactors;
    }

    public List<BusinessRequest> getBusinessRequests()
    {
        return businessRequests;
    }

    public void setBusinessRequests(List<BusinessRequest> businessRequests)
    {
        this.businessRequests = businessRequests;
    }

    public OrgRelaPersonService getOrgRelaPersonService()
    {
        return orgRelaPersonService;
    }

    public void setOrgRelaPersonService(OrgRelaPersonService orgRelaPersonService)
    {
        this.orgRelaPersonService = orgRelaPersonService;
    }

    public List<BusinessRequest> getYueBusinessRequests()
    {
        return yueBusinessRequests;
    }

    public void setYueBusinessRequests(List<BusinessRequest> yueBusinessRequests)
    {
        this.yueBusinessRequests = yueBusinessRequests;
    }
    
    public String getIsIndex()
    {
        return isIndex;
    }

    public void setIsIndex(String isIndex)
    {
        this.isIndex = isIndex;
    }

    public String getBusinessType()
    {
        return businessType;
    }

    public void setBusinessType(String businessType)
    {
        this.businessType = businessType;
    }

}
